<script setup lang='ts'>
  import { onMounted, reactive } from 'vue';
  import { statisticsApi } from '@/api/controller';
  import { ToastWarning, Toastloading } from '@/utils/public';
  import { getPlayEndTime, getDateArray } from '@/utils'
  import Pagination from "@/components/Pagination/index.vue";
  import xmDatePicker from '@/components/xmDatePicker/index.vue';
  const action = reactive({
    total:0,
    list:[] as any[],
    timeObj:getPlayEndTime(getDateArray('ymd')),
  })
  const listQuery = reactive({
    uuid:'',
    user_id:'',
    page:1,
    limit:20,
  })
  const handleSerach = ()=>{
    listQuery.page = 1
    getList()
  }
  const decimalCount = (num:number=0)=>{
    if(!num) return '0%'
    return (num*100).toFixed(0) + '%'
  }
  const getList = async()=> {
    const { uuid, user_id } = listQuery
    if(!uuid && !user_id) return ToastWarning('请输入用户ID或用户UUID后查询')
    const loading = Toastloading()
    const { playTime:date_st, endTime:date_ed } = action.timeObj
    const res = await statisticsApi.statUserInfo({
      date_st,
      date_ed,
      ...listQuery
    })
    loading.close()
    const { list=[], total=0 } = res.data
    action.total = total
    action.list = list
  }
</script>

<template>
  <div class="xm-content">
    <div class="xm-headTab">
      <div class="labelBox">
        <div class="labelItem">
          <div class="label">用户ID：</div>
          <el-input v-model="listQuery.user_id" placeholder="请输入用户ID" ></el-input>
        </div>
        <div class="labelItem">
          <div class="label">用户UUID：</div>
          <el-input v-model="listQuery.uuid" placeholder="请输入用户UUID" ></el-input>
        </div>
        <xmDatePicker type="daterange" v-model:timeval="action.timeObj" />
        <div class="labelItem">
          <el-button type="primary" @click="handleSerach">查询</el-button>
        </div>
      </div>
    </div>
    <el-table class="xm-main xm-TableCenter" :data="action.list" border>
      <el-table-column min-width="120" prop="nickname" label="用户昵称" fixed />
        <el-table-column width="100" prop="userId" label="用户ID" />
        <el-table-column width="100" prop="uuid" label="用户uuid" />
        <el-table-column min-width="120" prop="joinNum" label="参与次数" />
        <el-table-column min-width="120" prop="stakeNumAll" label="参与次数" />
        <el-table-column min-width="120" prop="stakeNum" label="成功次数" />
        <el-table-column min-width="130" prop="stakePriceAll" label="消耗金豆数量" />
        <el-table-column min-width="130" prop="rewardPriceAll" label="产出金豆数量" />
        <el-table-column min-width="130" prop="porfitNum" label="利润金豆数量" />
        <el-table-column min-width="120" prop="porfitRate" label="利润率" >
          <template #default="scope"> {{ decimalCount(scope.row.porfitRate) }} </template>
        </el-table-column>
        <el-table-column min-width="150" prop="exec_url" label="下载链接" />
    </el-table>
    <Pagination v-show="action.total > 0" :total="action.total" v-model:page="listQuery.page"
      v-model:limit="listQuery.limit" @pagination="getList" />
  </div>
</template>
